import RTRequest from './index'
import { RTRequestConfig } from './requestTypes'
export default function (
  RTRequestInstance: RTRequest,
  config: RTRequestConfig
): void {
  RTRequestInstance.interceptors = config.interceptors
  // 这里的后面的 instance 是 axios 的实例
  RTRequestInstance.instance.interceptors.request.use(
    RTRequestInstance.interceptors?.requestInterceptor,
    RTRequestInstance.interceptors?.requestInterceptorCatch
  )
  RTRequestInstance.instance.interceptors.response.use(
    RTRequestInstance.interceptors?.responseInterceptor,
    RTRequestInstance.interceptors?.responseInterceptorCatch
  )
  // 添加所有实例都应有的拦截器
  RTRequestInstance.instance.interceptors.request.use(
    (config) => {
      return config
    },
    (err) => {
      return err
    }
  )
  RTRequestInstance.instance.interceptors.response.use(
    (res) => {
      return res.data
    },
    (err) => {
      return err
    }
  )
}
